package com.scopionstudio.housemusic.parser;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.scopionstudio.housemusic.R;
import com.scopionstudio.housemusic.data.objData;
import android.content.Context;
import android.util.Log;

public class ParserMusic {
	Context mContext;
	ParserJson parser;
	String json;
	ArrayList<objData> arrayData;
	public ParserMusic(Context ctx){
		this.mContext=ctx;
		parser=new ParserJson();
		arrayData=new ArrayList<objData>();
	}
	public ArrayList<objData> getData(int page){
		String link = mContext.getString(R.string.link_music);
		json=parser.getJson(link + page);
		Log.e("TEST: ", ""+json);
		try {
			JSONObject jsonObject=new JSONObject(json);
			if(jsonObject!=null){
				
				JSONArray jsonArray=jsonObject.getJSONArray("nonstop");
				if(jsonArray.length()>0){
					for(int i=0;i<jsonArray.length();i++){
						JSONObject j=jsonArray.getJSONObject(i);
						objData data=new objData();
						Log.e("TEST: ", j.getString("name"));
						data.setName(j.getString("name"));
						data.setPage(page);
						data.setUrl(j.getString("detail"));
						arrayData.add(data);
					}
					
				}
				
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return arrayData;
		
		
	}
}
